< previous page page_125 next page >

Page 125
Required Fields
Almost every form has at least one field that is required input. Some forms may have several. Checking for required input fields is done at the form level. Let's add code at the cmdOK_click event that makes sure that users fill out the Combined field every time.
All you need to do is validate that the txtCombined field contains valid data. Listing 5.8 shows how this is done.
Type.gifListing 5.8. The form-level validation routine to check for required fields.
Private Sub cmdOK_Click()
    '
    Dim intHigh As Integer
    Dim intLow As Integer
    Dim strHighLowMsg As String
    '
    Dim intMinLen As Integer
    Dim intMaxLen As Integer
    Dim strMinMaxMsg As String
    '
    Dim blnOK As Boolean
    '
    intHigh = 100
    intLow = 1
    strHighLowMsg = "High/Low field must contain a value between " & _
       CStr(intLow) & " and " & CStr(intHigh)
    '
    intMinLen = 3
    intMaxLen = 10
    strMinMaxMsg = "Upper field must be between " & _
       CStr(intMinLen) & " and " & CStr(intMaxLen) & " long."
    '
    blnOK = False
    '
    ' check high/low field
    If Val(txtHighLow) < intLow Or Val(txtHighLow) > intHigh Then
        MsgBox strHighLowMsg
        blnOK = False
        txtHighLow.SetFocus
    End If
    '
    ' check upper field
    If Len(txtUpper) < intMinLen Or Len(txtUpper) > intMaxLen Then
        MsgBox strMinMaxMsg
continues

 
< previous page page_125 next page >

If you like this book, buy it!